<template>
  <div>
    <p class="tip">虚拟滚动渲染，键盘移动高亮行，设置 <table-api-link prop="keyboard-config"/>={isArrow: true} 启用方向键功能</p>

    <vxe-table
      border
      resizable
      show-overflow
      highlight-current-row
      ref="xTable"
      height="300"
      :loading="loading"
      :keyboard-config="{isArrow: true}">
      <vxe-table-column type="seq" width="100"></vxe-table-column>
      <vxe-table-column prop="name" label="Name" sortable width="200"></vxe-table-column>
      <vxe-table-column prop="age" label="Age" width="200"></vxe-table-column>
      <vxe-table-column prop="sex" label="Sex" width="200"></vxe-table-column>
      <vxe-table-column prop="rate" label="Rate" width="200"></vxe-table-column>
      <vxe-table-column prop="region" label="Region" width="200"></vxe-table-column>
      <vxe-table-column prop="time" label="Time" width="200"></vxe-table-column>
      <vxe-table-column prop="address" label="Address" width="300" show-overflow></vxe-table-column>
      <vxe-table-column prop="updateTime" label="UpdateTime" width="200"></vxe-table-column>
      <vxe-table-column prop="createTime" label="CreateTime" width="200"></vxe-table-column>
    </vxe-table>

    <pre>
      <code>
        | Arrow Up ↑ | 移动到高亮行的上一行 |
        | Arrow Down ↓ | 移动到高亮行的下一行 |
      </code>
    </pre>

    <p class="demo-code">{{ $t('app.body.button.showCode') }}</p>

    <pre>
      <code class="xml">{{ demoCodes[0] }}</code>
      <code class="javascript">{{ demoCodes[1] }}</code>
    </pre>
  </div>
</template>

<script>
import hljs from 'highlight.js'

export default {
  data () {
    return {
      loading: false,
      demoCodes: [
        `
        <vxe-table
          border
          resizable
          show-overflow
          highlight-current-row
          ref="xTable"
          height="300"
          :loading="loading"
          :keyboard-config="{isArrow: true}">
          <vxe-table-column type="seq" width="100"></vxe-table-column>
          <vxe-table-column prop="name" label="Name" sortable width="200"></vxe-table-column>
          <vxe-table-column prop="age" label="Age" width="200"></vxe-table-column>
          <vxe-table-column prop="sex" label="Sex" width="200"></vxe-table-column>
          <vxe-table-column prop="rate" label="Rate" width="200"></vxe-table-column>
          <vxe-table-column prop="region" label="Region" width="200"></vxe-table-column>
          <vxe-table-column prop="time" label="Time" width="200"></vxe-table-column>
          <vxe-table-column prop="address" label="Address" width="300" show-overflow></vxe-table-column>
          <vxe-table-column prop="updateTime" label="UpdateTime" width="200"></vxe-table-column>
          <vxe-table-column prop="createTime" label="CreateTime" width="200"></vxe-table-column>
        </vxe-table>
        `,
        `
        export default {
          data () {
            return {
              loading: false
            }
          },
          created () {
            this.loading = true
            setTimeout(() => {
              let tableData = window.MOCK_DATA_LIST.slice(0, 600)
              // 使用函数式加载，阻断 vue 对大数组的监听，大数据性能翻倍提升
              if (this.$refs.xTable) {
                this.$refs.xTable.loadData(tableData)
              }
              this.loading = false
            }, 300)
          }
        }
        `
      ]
    }
  },
  created () {
    this.loading = true
    setTimeout(() => {
      let tableData = window.MOCK_DATA_LIST.slice(0, 600)
      // 阻断 vue 对大数组的监听，大数据性能翻倍提升
      if (this.$refs.xTable) {
        this.$refs.xTable.loadData(tableData)
      }
      this.loading = false
    }, 300)
  },
  mounted () {
    Array.from(this.$el.querySelectorAll('pre code')).forEach((block) => {
      hljs.highlightBlock(block)
    })
  }
}
</script>
